package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.controller.form.RulePageForm;
import com.woniuxy.controller.info.RoleInfo;
import com.woniuxy.model.Role;
import com.woniuxy.dao.RoleDao;
import com.woniuxy.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.utils.NewCopyBean;
import com.woniuxy.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hujianying
 * @since 2022-03-23
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleService {

    @Resource
    private  RoleDao ruleDao;
    @Override
    public Result findRuleByPage(RulePageForm rpf) {
        //分页
        Page<Role> pageForm = ruleDao.selectPage(rpf, null);
        Page<RoleInfo> ruleInfoPage = new Page<>();
        List<RoleInfo> ruleInfos = NewCopyBean.copyList(pageForm.getRecords(), RoleInfo.class);
        //设置真实数据
        System.out.println(ruleInfos);
        ruleInfoPage.setRecords(ruleInfos);
        ruleInfoPage.setCurrent(pageForm.getCurrent());
        ruleInfoPage.setTotal(pageForm.getTotal());
        ruleInfoPage.setSize(pageForm.getSize());
        ruleInfoPage.setPages(pageForm.getPages());
        return Result.success(200,"查询成功",ruleInfoPage);
    }
}
